/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package meteocal.gui;

import java.io.Serializable;
import java.security.Principal;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.enterprise.context.SessionScoped;
import javax.inject.Inject;
import javax.inject.Named;
import meteocal.business.boundary.UserFacade;
import meteocal.business.entity.Event;
import meteocal.business.security.boundary.UserManager;
import meteocal.business.security.entity.User;

/**
 *
 * @author luana
 */

@Named
@SessionScoped
public class SearchBean implements Serializable {
    
   
    private List<User> currentUserList;
    private User selectedUser;
    private String keywordUsername="";
    private String keywordName="";
    private String keywordCity="";
    private Event selectedEvent;
    
    private static final long serialVersionUID = 1L;

    
    @EJB
    UserFacade uf;
    
    @EJB
    UserManager um; 
    
    @Inject 
    Principal principal;
    
    
    public SearchBean() {    }    
    
    public String getKeywordUsername() {
        return keywordUsername;
    }

    public void setKeywordUsername(String keywordUsername) {
        this.keywordUsername = keywordUsername;
    }

    public String getKeywordName() {
        return keywordName;
    }

    public void setKeywordName(String keywordName) {
        this.keywordName = keywordName;
    }

    public String getKeywordCity() {
        return keywordCity;
    }

    public void setKeywordCity(String keywordCity) {
        this.keywordCity = keywordCity;
    }
    
    
    public User getSelectedUser() {
        return selectedUser;
    }

    public void setSelectedUser(User selectedUser) {
        this.selectedUser = selectedUser;
    }

    public void setCurrentUserList(List<User> currentUserList) {
        this.currentUserList = currentUserList;
    }
    
    public List<User> getCurrentUserList() {
        return currentUserList;
    }
     
    public String browseUsers(){     
        currentUserList = uf.getAllUser();
        currentUserList.remove(um.find(principal.getName()));
        return "search-page?faces-redirect=true";
    }
     
    public void searchUsername(){
       currentUserList = uf.searchUserUsername(keywordUsername); 
        
    }   
    
    public void searchName(){
      
        currentUserList = uf.searchUserName(keywordName);
    }
    
     public void searchCity(){
        
       currentUserList = uf.searchUserCity(keywordCity);
    }
  
}
